﻿using System;
using Ninject.Activation;
using Ninject.Extensions.Interception;
using Ninject.Extensions.Interception.Infrastructure.Language;

namespace Nb.Common.Aop
{
    public class ExecuteTimingInterceptionModule : InterceptionModule
    {
        public override void Load()
        {
            var enableIntercept = NbPerformanceTraceFacade.PerformanceTraceEnabled();
            if (enableIntercept)
            {
                //NbInterceptFacade.Config();
                Kernel.Intercept(context =>
                {

                    var shouldIntercept = NbPerformanceTraceFacade.ShouldIntercept(context.Request.Service);
                    return shouldIntercept;
                })
                //.With(CreateInterceptor());
                .With(request => new ExecuteTimingInterceptor());
            }
        }
    }
}
